package com.jyw.business.ins.controller;

import java.util.List;

import com.jyw.business.ast.domain.dto.web.AstItemPageDto;
import com.jyw.business.ast.domain.vo.web.AstItemPageVo;
import com.jyw.business.ins.domain.dto.web.ItemAddDto;
import com.jyw.business.ins.domain.dto.web.ItemEditDto;
import com.jyw.business.ins.domain.dto.web.ItemListDto;
import com.jyw.business.ins.domain.dto.web.UnitItemPageDto;
import com.jyw.business.ins.domain.vo.web.ItemListVo;
import com.jyw.business.ins.domain.vo.web.UnitItemPageVo;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.BasePage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.enums.BusinessType;
import com.jyw.business.ins.domain.InsConfigItem;
import com.jyw.business.ins.service.IInsConfigItemService;
import com.jyw.common.core.page.TableDataInfo;

/**
 * 巡检配置项Controller
 * 
 * @author system
 * @date 2023-09-20
 */
@RestController
@RequestMapping("/ins/item")
@Api(tags = "配置巡检项")
public class InsConfigItemController extends BaseController
{
    @Autowired
    private IInsConfigItemService insConfigItemService;

    /**
     * 查询巡检配置项列表
     */
    @PreAuthorize("@ss.hasPermi('ins:item:list')")
    @GetMapping("/ast/list")
    @ApiOperation("配置巡检项资产查询")
    public TableDataInfo<AstItemPageVo> astList(BasePage page, AstItemPageDto dto)
    {
        if(!ObjectUtils.isEmpty(page)){
            startPage();
        }
        List<AstItemPageVo> list = insConfigItemService.astList(dto);
        return getDataTable(list);
    }

    /**
     * 查询巡检配置项列表
     */
    @PreAuthorize("@ss.hasPermi('ins:item:list')")
    @GetMapping("/unit/list")
    @ApiOperation("配置巡检项巡检单元查询")
    public TableDataInfo<UnitItemPageVo> unitList(BasePage page, UnitItemPageDto dto)
    {
        if(!ObjectUtils.isEmpty(page)){
            startPage();
        }
        List<UnitItemPageVo> list = insConfigItemService.unitList(dto);
        return getDataTable(list);
    }


    /**
     * 查询巡检配置项列表
     */
    @PreAuthorize("@ss.hasPermi('ins:item:list')")
    @GetMapping("/list")
    @ApiOperation("当前巡检项查询")
    public CommonResult<List<ItemListVo>> list(@Validated ItemListDto dto)
    {
        List<ItemListVo> list = insConfigItemService.list(dto);
        return CommonResult.success(list);
    }

    /**
     * 获取巡检配置项详细信息
     */
    @PreAuthorize("@ss.hasPermi('ins:item:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取配置项详情")
    public CommonResult<InsConfigItem> getInfo(@PathVariable("id") Long id)
    {
        return CommonResult.success(insConfigItemService.selectInsConfigItemById(id));
    }

    /**
     * 新增巡检配置项
     */
    @PreAuthorize("@ss.hasPermi('ins:item:add')")
    @Log(title = "巡检配置项", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增巡检配置项")
    public CommonResult add(@RequestBody @Validated ItemAddDto addDto)
    {
        insConfigItemService.save(addDto.buildConfigItem());
        return CommonResult.success();
    }

    /**
     * 修改巡检配置项
     */
    @PreAuthorize("@ss.hasPermi('ins:item:edit')")
    @Log(title = "巡检配置项", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("编辑巡检项")
    public CommonResult edit(@RequestBody ItemEditDto editDto)
    {
        insConfigItemService.updateById(editDto.buildConfigItem());
        return CommonResult.success();
    }

    /**
     * 删除巡检配置项
     */
    @PreAuthorize("@ss.hasPermi('ins:item:remove')")
    @Log(title = "巡检配置项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除巡检项")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return CommonResult.success(insConfigItemService.deleteInsConfigItemByIds(ids));
    }
}
